package com.applet.applet_shangcheng.dao;

import com.applet.applet_shangcheng.entity.Goods;
import com.applet.applet_shangcheng.entity.GoodsClass;
import com.applet.applet_shangcheng.entity.ShufflingFigure;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;

import java.util.List;

@Mapper
public interface GoodsMapper {
    @Select({
            "SELECT id,goods_id,goods_name,image,price,connection,images,goods_introduce,goods_details,create_time,update_time,integral,remit,sale_num,status FROM tb_goods"
    })
    List<Goods> findAll();

    @Select({
            "SELECT id,goods_id,goods_name,image,price,connection,images,goods_introduce,goods_details,create_time,update_time,integral,remit,sale_num,status FROM tb_goods where status =1"
    })
    List<Goods> findAllShelves();

    @Select({
            "SELECT id,goods_id,goods_name,image,price,connection,images,goods_introduce,goods_details,create_time,update_time,integral,remit,sale_num,status FROM tb_goods where goods_id =#{goodsId}"
    })
    Goods findById(@Param("goodsId") int goodsId);

    @Insert({
            "insert into tb_goods (goods_id,goods_name,image,price,connection,images,goods_introduce,goods_details,create_time,update_time,integral,remit,sale_num,status) values(#{goodsId},#{goodsName},#{image},#{price},#{connection},#{images},#{goodsIntroduce},#{goodsDetails},#{createTime},#{updateTime},#{integral},#{remit},#{saleNum},#{status})"
    })
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertGoods(Goods goods);

    @Update({
            "update tb_goods set goods_name=#{goodsName},image=#{image},price=#{price},connection=#{connection},images=#{images},goods_introduce=#{goodsIntroduce},goods_details=#{goodsDetails},update_time=#{updateTime},integral=#{integral},remit=#{remit},sale_num=#{saleNum},status=#{status} where id=#{id}"
    })
    int updateGoods(Goods goods);

    @Update({
            "update tb_goods set status=#{status} where id = #{id}"
    })
    int updateStatus(@Param("id") int id, @Param("status") int status);

    @Delete({
            "delete from tb_goods where id=#{id}"
    })
    int deleteGoods(@Param("id") int id);

    @Select({
            "SELECT id,goods_id,goods_name,image,price,connection,images,goods_introduce,goods_details,create_time,update_time,integral,remit,sale_num,status FROM tb_goods where goods_id =#{goodsId}"
    })
    Goods findGoods(@Param("goodsId") int goodsId);

    Page<ShufflingFigure> findAlls(String queryString);

    @Update({
            "update tb_goods set connection = connection -#{sumNumber} where goods_id =#{goodsId}"
    })
    void updateGoodsNumber(@Param("sumNumber") int sumNumber, @Param("goodsId") String goodsId);

    @Select({
            "SELECT id,goods_id,goods_name,image,price,connection,images,goods_introduce,goods_details,create_time,update_time,integral,remit,sale_num,status FROM tb_goods where goods_name =#{goodsName}"
    })
    Goods findByGoodsName(@Param("goodsName") String goodsName);

    @Select({
            "SELECT id,goods_id,goods_name,image,price,connection,images,goods_introduce,goods_details,create_time,update_time,integral,remit,sale_num,status FROM tb_goods where id =#{id}"
    })
    Goods findId(@Param("id") int id);

    @Update({
            "update tb_goods set connection = connection-#{number} where goods_id=#{goodsId} and number>connection"
    })
    int updateNumber(@Param("goodsId") int goodsId, @Param("number") int number);

    @Insert({
            "insert into tb_goods_class (goods_id,social,students,soldier,status) values (#{goodsId},#{social},#{students},#{soldier},#{status})"
    })
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertGoodsClass(GoodsClass goodsClass);

    @Select({
            "select * from tb_goods_class where goods_id = #{goodsId}"
    })
    GoodsClass findByGoodsId(@Param("goodsId") int goodsId);

    @Update({
            "update tb_goods_class set social=#{social},students=#{students},soldier=#{soldier},status=#{status} where goods_id = #{goodsId}"
    })
    int updateGoodsClass(GoodsClass goodsClass);

    @Delete({
            "delete from tb_goods_class where goods_id = #{goodsId}"
    })
    int deleteGoodsClass(@Param("goodsId") int goodsId);
}











